package uc

import (
	"sync"
	"time"
	"wzgames/pkg/actor/actor"
	"wzgames/pkg/actor/actorservice"
	"wzgames/pkg/common/timingwheel"
)

var (
	ucGuard *UcGuard
	once    sync.Once
)

type UcGuard struct {
	actorservice.ServiceMeta

	timerWheel *timingwheel.TimingWheel
}

func Actor() actorservice.IService {
	if ucGuard == nil {
		once.Do(func() {
			ucGuard = &UcGuard{
				timerWheel: timingwheel.NewTimingWheel(time.Second, 60),
			}
			ucGuard.Name = "actor_uc_guard"
		})
	}
	return ucGuard
}

func (u *UcGuard) OnReceive(ctx actor.Context) {

}

func (u *UcGuard) OnStart(as *actorservice.ActorService) {
	u.timerWheel.Start()
}

func (u *UcGuard) Attach(a interface{}) {

}

func (u *UcGuard) OnDestroy() {
	u.timerWheel.Stop()
	actorservice.Stop(u.GetPID())
}
